Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / desktop / src / main / kotlin / org / meshtastic / desktop / radio / DesktopMessageQueue.kt

Displaying Raw • Download

desktop/src/main/kotlin/org/meshtastic/desktop/radio/DesktopMessageQueue.kt a3c0a4832d139b9ed15cc2fdd22d9d2c0bef1db4 (a3c0a483) Text, 2.84 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.desktop.radio

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.CoroutineScope
Tff7b72import T7ee787kotlinx.coroutines.Dispatchers
Tff7b72import T7ee787kotlinx.coroutines.SupervisorJob
Tff7b72import T7ee787kotlinx.coroutines.launch
Tff7b72import T7ee787org.meshtastic.core.model.ConnectionState
Tff7b72import T7ee787org.meshtastic.core.model.MessageStatus
Tff7b72import T7ee787org.meshtastic.core.model.RadioController
Tff7b72import T7ee787org.meshtastic.core.repository.MessageQueue
Tff7b72import T7ee787org.meshtastic.core.repository.PacketRepository

T8b949e/**
* Desktop implementation of [MessageQueue].
*
* Unlike Android which uses WorkManager to ensure delivery across app lifecycles, Desktop immediately delegates to the
* active controller to send the message.
*/
Tff7b72class T56d364DesktopMessageQueueTb4b4b4(
Tff7b72private Tff7b72val Te6edf3packetRepositoryTb4b4b4: Te6edf3PacketRepositoryTb4b4b4,
Tff7b72private Tff7b72val Te6edf3radioControllerTb4b4b4: Te6edf3RadioControllerTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3MessageQueue Tb4b4b4{
Tff7b72private Tff7b72val Te6edf3scope Tff7b72= Te6edf3CoroutineScopeTb4b4b4(Te6edf3SupervisorJobTb4b4b4(Tb4b4b4) Tff7b72+ Te6edf3DispatchersTb4b4b4.Te6edf3IOTb4b4b4)

Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffenqueueTb4b4b4(Te6edf3packetIdTb4b4b4: Tffa657IntTb4b4b4) Tb4b4b4{
Te6edf3scopeTb4b4b4.Te6edf3launch Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3packetId Tff7b72=Tff7b72= T79c0ff0Tb4b4b4) Tff7b72returnTf0883e@launch

T8b949e// Verify we are connected before attempting to send to avoid unnecessary Exception bubbling
Tff7b72if Tb4b4b4(Te6edf3radioControllerTb4b4b4.Te6edf3connectionStateTb4b4b4.Te6edf3value Tff7b72!Tff7b72= Te6edf3ConnectionStateTb4b4b4.Te6edf3ConnectedTb4b4b4) Tb4b4b4{
T8b949e// In a real desktop environment, we might want a background loop to retry queued messages.
T8b949e// For now, it will retry when connection is re-established (handled by
T8b949e// MeshConnectionManager.onRadioConfigLoaded).
Tff7b72returnTf0883e@launch
Tb4b4b4}

Tff7b72val Te6edf3packetData Tff7b72=
Te6edf3packetRepositoryTb4b4b4.Te6edf3getPacketByPacketIdTb4b4b4(Te6edf3packetIdTb4b4b4)
Tff7b72?: Tff7b72returnTf0883e@launch T8b949e// Packet no longer exists in DB? Do not retry.

Tff7b72try Tb4b4b4{
Te6edf3radioControllerTb4b4b4.Te6edf3sendMessageTb4b4b4(Te6edf3packetDataTb4b4b4)
Te6edf3packetRepositoryTb4b4b4.Te6edf3updateMessageStatusTb4b4b4(Te6edf3packetDataTb4b4b4, Te6edf3MessageStatusTb4b4b4.Te6edf3ENROUTETb4b4b4)
Tb4b4b4} Tff7b72catch Tb4b4b4(Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffTooGenericExceptionCaughtTa5d6ff"Tb4b4b4) Te6edf3eTb4b4b4: Te6edf3ExceptionTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffFailed to send packet Tffd700${Te6edf3packetDataTb4b4b4.Te6edf3idTffd700}Ta5d6ff, re-queuingTa5d6ff" Tb4b4b4}
Te6edf3packetRepositoryTb4b4b4.Te6edf3updateMessageStatusTb4b4b4(Te6edf3packetDataTb4b4b4, Te6edf3MessageStatusTb4b4b4.Te6edf3QUEUEDTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.2 - Generated in 0.1s